package org.opens.javaskill.thread.api;

public class ThreadApi {

    public static void main(String[] args) {
        Thread thread = new Thread(() -> {
            System.out.println("hello world");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, "t1");
        thread.start();
        System.out.println("name: " + thread.getName());
        System.out.println("id: " + thread.getId());
        System.out.println("优先级: " + thread.getPriority());
    }

}

class ApiTest2 {

    public static void main(String[] args) {
        Thread thread1 = new Thread(() -> {
            for (int i = 0; i < 1000; i++) {
                System.out.println("线程" + Thread.currentThread().getName() + " " + i);

            }
        }, "t1");
        Thread thread2 = new Thread(() -> {
            for (int i = 0; i < 1000; i++) {
                System.out.println("线程 " + Thread.currentThread().getName() + " " + i);

            }
        }, "t2");
        Thread thread3 = new Thread(() -> {
            for (int i = 0; i < 1000; i++) {
                System.out.println("线程" + Thread.currentThread().getName() + " " + i);

            }
        }, "t3");

        thread1.setPriority(Thread.MAX_PRIORITY);
        thread2.setPriority(Thread.NORM_PRIORITY);
        thread3.setPriority(Thread.MIN_PRIORITY);

        thread1.start();
        thread2.start();
        thread3.start();
    }

}
